//
//  WQVerticalBtn.m
//  MeterCircle
//
//  Created by 魏强 on 16/6/28.
//  Copyright © 2016年 魏强. All rights reserved.
//

#import "WQVerticalBtn.h"

@implementation WQVerticalBtn


// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
//- (void)drawRect:(CGRect)rect {
//    // Drawing code
//    
//}
- (void)setImageAndTitleLeft:(float)spacing {
    CGSize imageSize = self.imageView.frame.size;
    CGSize titleSize = self.titleLabel.frame.size;
    
    CGFloat totalHeight = (imageSize.height + titleSize.height + spacing);
    
    self.imageEdgeInsets = UIEdgeInsetsMake( - (totalHeight - imageSize.height), 0.0, 0.0, - titleSize.width);
    
    self.titleEdgeInsets = UIEdgeInsetsMake( 0.0, - imageSize.width, - (totalHeight - titleSize.height), 0.0);
}

- (void)setImageAndTitleLeft{
    const int SPACING = 2.0f;
    [self setImageAndTitleLeft:SPACING];
}
- (void)test{
    //titleLabel和imageView之间的高度间隔
//    WQLog(@"%@, %@", self.titleLabel.text, NSStringFromCGRect(self.frame));
    CGFloat margin = 10.0;
    self.imageView.center = CGPointMake(self.width *0.5, (self.height - margin - self.imageView.height - self.titleLabel.height) * 0.5 + self.imageView.height * 0.5 );
    self.titleLabel.center = CGPointMake(self.width *0.5, CGRectGetMaxY(self.imageView.frame) + margin + self.titleLabel.height *0.5);
}
- (void)layoutSubviews{
    [super layoutSubviews];
   [self setImageAndTitleLeft];
    
}
@end
